//
//  SentCommandViewController.swift
//  TJJPT
//
//  Created by FENGYL on 2017/7/14.
//  Copyright © 2017年 FENGYL. All rights reserved.
//

import UIKit

class SentCommandViewController: UIViewController {
    
    @IBOutlet weak var statusButton: UIButton!
    @IBOutlet weak var commandStatusButton: UIButton!
    @IBOutlet weak var commandTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        setUpView()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    // MARK: - 初始化
    func setUpView() {
        
        // MARK: 右上角按钮名字
        if UserModel.userModel.devicesByAccountArray != nil {
            
            if (UserModel.userModel.devicesByAccountArray?.count)! > 0 {
                
                for dict in UserModel.userModel.devicesByAccountArray! {
                    
                    
                    let devicesByAccount = DevicesByAccount.mj_object(withKeyValues: dict)
                    
                    let serialNumber = devicesByAccount?.SerialNumber ?? ""
                    
                    if serialNumber == UserModel.userModel.selectedDeviceSerialNumber {
                        
                        statusButton.setTitle(devicesByAccount?.DisplayName ?? serialNumber, for: .normal)
                        
                    }
                    
                    
                    
                }
                
                
            }
            
        }
        
        // MARK: 线上状态
        if UserModel.userModel.lastStatusDataArray != nil {
            
            if (UserModel.userModel.lastStatusDataArray?.count)! > 0 {
                
                for dict in UserModel.userModel.lastStatusDataArray! {
                    
                    let lastStatusData = LastStatusData.mj_object(withKeyValues: dict)
                    
                    let serialNumber = lastStatusData?.SerialNumber ?? ""
                    
                    if serialNumber == UserModel.userModel.selectedDeviceSerialNumber {
                        
                        let connStatus = lastStatusData?.ConnStatus
                        
                        if connStatus == 1 {
                            
                            statusButton.setImage(#imageLiteral(resourceName: "z_gps_Status_online"), for: .normal)
                            
                        }else if connStatus == 0 {
                            
                            statusButton.setImage(#imageLiteral(resourceName: "z_gps_Status_outline"), for: .normal)
                            
                        }
                        
                    }
                    
                }
                
            }
            
        }
        
        // MARK: - 标题
        
        self.title = NSLocalizedString(LOCALIZABLE_STRING_ONLINE_COMMAND, comment: "")
        
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
